<?php
/**
 * @package: Asalsuri
 * @subpackage: Admin Model
 * @author: Nguyen Thanh Tung
 * @date: January 24, 2014 - January 27, 2014
 * 
*/
class Uniform_Model extends CI_Model{
	var $database;
	public function __construct() {
        parent::__construct();
		$this->database = $this->db->conn_id;
		
	}
	 /**
    * @author: Nguyen Thanh Tung
    * @description: get  stadium
    * @param integer $intStadiumId: 
    * @param array
    */
	public function get($intUniformId) {
		$stmt = $this->database->prepare('call clubs_uniform_get(?)');		
		$stmt->bindParam(1, $intUniformId, PDO::PARAM_INT, 11);
        $stmt->execute();
		$arrResult 	= $stmt->fetch();			
		return isset($arrResult) ? $arrResult : null;		
	}
    /**
    * @author: Nguyen Thanh Tung
    * @description: get all stadium
    * @param integer $intType: 
    * @param integer $intOffset: o
    * @param integer $intLimit: 
    * @param integer $intTotal: assign found rows 
    * @param array
    */
	
    public function getAll($intLoginId,$intStatus,$intClubId,$strStartDate,$strEndDate,$intOffset, $intLimit, &$intTotal=0) {
		$stmt = $this->database->prepare('CALL clubs_uniform_getall_a(?,?,?,?,?,
																	?,?)');
		$stmt->bindParam(1, $intLoginId,   PDO::PARAM_INT);
		$stmt->bindParam(2, $intStatus,    PDO::PARAM_INT);
		$stmt->bindParam(3, $intClubId,    PDO::PARAM_INT);		
		$stmt->bindParam(4, $strStartDate, PDO::PARAM_STR);		
		$stmt->bindParam(5, $strEndDate,   PDO::PARAM_STR);		
		$stmt->bindParam(6, $intOffset,    PDO::PARAM_INT);		
		$stmt->bindParam(7, $intLimit,     PDO::PARAM_INT);		
		$stmt->execute();
		$result = $stmt->fetchAll();        
		$intTotal = isset($result[0]['foundRows']) ? $result[0]['foundRows'] : 0;
		return isset($result) ? $result : null;
	}
	/**
     * @author: Nguyen Thanh Tung
	 * @description: add stadium 
	 * @param interger $intLoginId: id admin loggin (as root id width insert permission)
	 * @param integer $intClubId
	 * @param string $strStadiumname
	 * @param string $strStadiumnShort
	 * @param string $strStadiumDescription
     * @param integer $intActive
     * @param integer $intOpacity
     * @param string $strStadiumOpenDate
     * @param string $strStadiumCloseDate
	 * @return integer
     *    0: INSERT SUCCESS
     *    1: ERROR - NOT PERMISSION UPDATE
     *      	
	 */
	
	public function add($intLoginId,$intClubId, $intFrom, $intTo, $intHomeShirt, $strShort, $strDescription) {
		$stmt = $this->database->prepare('CALL clubs_uniform_add(?,?,?,?,?,
																	?,?)');														
		$stmt->bindParam(1, $intLoginId,     PDO::PARAM_INT);
		$stmt->bindParam(2, $intClubId,      PDO::PARAM_INT);
		$stmt->bindParam(3, $intFrom,        PDO::PARAM_INT);
		$stmt->bindParam(4, $intTo,          PDO::PARAM_INT);
		$stmt->bindParam(5, $intHomeShirt,   PDO::PARAM_INT,4);		
		$stmt->bindParam(6, $strShort,       PDO::PARAM_STR, 255);		
		$stmt->bindParam(7, $strDescription, PDO::PARAM_STR);		
		$stmt->execute();	
        $result = $stmt->fetch();
        return isset($result['errCode']) ? $result['errCode'] : -1;	
	}
	/**
     * @author: Nguyen Thanh Tung
	 * @description: update stadium 
	 * @param interger $intLoginId: id admin loggin (as root id width insert permission)
     * @param integer $intStadiumId
	 * @param integer $intClubId
	 * @param string $strStadiumname
	 * @param string $strStadiumnShort
	 * @param string $strStadiumDescription
     * @param integer $intActive
     * @param integer $intOpacity
     * @param string $strStadiumOpenDate
     * @param string $strStadiumCloseDate
	 * @return integer
     *    0: INSERT SUCCESS
     *    1: ERROR - NOT PERMISSION UPDATE
     *      	
	 */
	public function update($intLoginId, $intUniformId, $intClubId, $strFromYear, $strToYear, $intHomeShirt, $strShort, $strDescription) {
		$stmt = $this->database->prepare('CALL clubs_uniform_update(?,?,?,?,?,
                                                             ?,?,?)');
		$stmt->bindParam(1, $intLoginId, 		 PDO::PARAM_INT);
		$stmt->bindParam(2, $intUniformId,  	 PDO::PARAM_INT);
		$stmt->bindParam(3, $intClubId,		     PDO::PARAM_INT);
		$stmt->bindParam(4, $strFromYear, 		 PDO::PARAM_STR);
		$stmt->bindParam(5, $strToYear,	         PDO::PARAM_STR);
		$stmt->bindParam(6, $intHomeShirt,  	 PDO::PARAM_INT,4);		
		$stmt->bindParam(7, $strShort,  		 PDO::PARAM_STR, 255);		
		$stmt->bindParam(8, $strDescription,  	 PDO::PARAM_STR);		
		$stmt->execute();
		$result = $stmt->fetch();
		return isset($result['errCode']) ? $result['errCode'] : -1;	
	}
	/**
     * @author: Nguyen Thanh Tung
	 * @description: update status
	 * @param interger $intLoginId: id admin loggin (as root id width insert permission)
     * @param integer $intStadiumId
     * @param integer $intStatus
     * @param integer $intPerm
	 * @return integer
     *    0: INSERT SUCCESS
     *    1: ERROR - NOT PERMISSION UPDATE
     *      	
	 */
	public function updateStatus($intLoginId, $intUniformId, $intStatus, $intPerm) {
		$stmt = $this->database->prepare('call clubs_uniform_update_status(?,?,?,?)');
		$stmt->bindParam(1, $intLoginId,   PDO::PARAM_INT, 11);
		$stmt->bindParam(2, $intUniformId, PDO::PARAM_INT, 11);
		$stmt->bindParam(3, $intStatus,    PDO::PARAM_INT, 4);
		$stmt->bindParam(4, $intPerm,      PDO::PARAM_INT, 4);
        $stmt->execute();
		$arrResult 	= $stmt->fetch();
		$intError	= isset($arrResult['errCode']) ? $arrResult['errCode'] : -1;
		if($intError == 0) {
		}
		return $intError;
	}
	/**
     * @author: Nguyen Thanh Tung
	 * @description: delete
	 * @param interger $intLoginId: 
     * @param integer $intStadiumId
	 * @return integer
     *    0:  SUCCESS
     *    1: ERROR - NOT PERMISSION 
     *      	
	 */
	public function delete($intLoginId, $intStadiumId) {
					
		$stmt = $this->database->prepare('call clubs_uniform_delete(?,?)');
		$stmt->bindParam(1, $intLoginId,   PDO::PARAM_INT, 11);
		$stmt->bindParam(2, $intStadiumId, PDO::PARAM_INT, 11);
        $stmt->execute();
		$arrResult 	= $stmt->fetch();
		$intError	= isset($arrResult['errCode']) ? $arrResult['errCode'] : -1;
		if($intError == 0) {
		}
		return $intError;
	}
	
	/**
	*	@description: get Error code from query result
	*	@param: mixed query result
	*	@return: int
	*/
	public function getErrorCode ( $tableData) {
		return isset($tableData['errCode'])?intval($tableData['errCode']):0;
	}	
	
}
